﻿'
' Boogaloo® - http://www.mindfly.com
' Copyright (c) 2008
' by Mindfly, Inc.
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
' INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
' DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
' SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
' SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
' WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
' THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Imports System.Xml
Imports Boogaloo.Core.UI
Imports Boogaloo.Core.BLL

Namespace UI.Controls

    Public Class CommitWizard
        Inherits CompositeControl
        Implements INamingContainer

        Public Event Click As EventHandler


        Protected Overrides Sub CreateChildControls()
            MyBase.CreateChildControls()

            _message = New LiteralControl
            _message.Text = "You need to commit to doing this action."

            _wrapper = New Label

            _panel = New Label
            _panel.cssclass = _container_cssclass
            _panel.Controls.Add(_message)
            _panel.Visible = False
            'Controls.Add(_panel)

            _wrapper.Controls.Add(_panel)

            _lb_commit = New LinkButton
            _lb_commit.CommandName = "Commit"
            _lb_commit.Text = "Commit"
            _lb_commit.CssClass = "button enriched"
            _lb_commit.Visible = False
            'Controls.Add(_lb_commit)
            _wrapper.Controls.Add(_lb_commit)

            _hyp_cancel = New HyperLink
            _hyp_cancel.NavigateUrl = HttpContext.Current.Request.Url.PathAndQuery
            _hyp_cancel.Text = "Cancel"
            _hyp_cancel.CssClass = "button enriched"
            _hyp_cancel.Visible = False
            'Controls.Add(_hyp_cancel)
            _wrapper.Controls.Add(_hyp_cancel)

            _lb_start = New LinkButton
            _lb_start.Text = "Start"
            _lb_start.CommandName = "ShowPanel"
            _lb_start.CausesValidation = False
            'Controls.Add(_lb_start)

            _wrapper.Controls.Add(_lb_start)

            Controls.Add(_wrapper)


        End Sub


        Protected Overrides Function OnBubbleEvent(ByVal source As Object, ByVal e As System.EventArgs) As Boolean

            Dim handled As Boolean = False
            If TypeOf e Is CommandEventArgs Then
                Dim ce As CommandEventArgs = CType(e, CommandEventArgs)
                If ce.CommandName = "Commit" Then
                    OnClick(ce)
                    handled = True
                ElseIf ce.CommandName = "ShowPanel" Then
                    _panel.Visible = True
                    _lb_commit.Visible = True
                    _hyp_cancel.Visible = True
                    _lb_start.Visible = False
                    MyBase.CssClass = MyBase.CssClass & " active"
                End If

            End If
            Return handled

        End Function


        Protected Overridable Sub OnClick(ByVal e As EventArgs)
            RaiseEvent Click(Me, e)
        End Sub

#Region "Properties"

        Private _wrapper As Label
        Public Property wrapper_cssclass() As String
            Get
                EnsureChildControls()
                Return _wrapper.CssClass
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _wrapper.CssClass = value
            End Set
        End Property



        Private _panel As Label
        Public Property container_visible() As Boolean
            Get
                EnsureChildControls()
                Return _panel.Visible
            End Get
            Set(ByVal value As Boolean)
                EnsureChildControls()
                _panel.Visible = value
            End Set
        End Property


        Private _lb_commit As LinkButton
        Public Property commit_text() As String
            Get
                EnsureChildControls()
                Return _lb_commit.Text
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _lb_commit.Text = value
            End Set
        End Property

        Public Property CommandArgument() As String
            Get
                EnsureChildControls()
                Return _lb_commit.CommandArgument
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _lb_commit.CommandArgument = value
            End Set
        End Property

        Private _lb_start As LinkButton
        Public Property start_text() As String
            Get
                EnsureChildControls()
                Return _lb_start.Text
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _lb_start.Text = value
            End Set
        End Property

        Private _hyp_cancel As HyperLink
        Public Property cancel_text() As String
            Get
                EnsureChildControls()
                Return _hyp_cancel.Text
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _hyp_cancel.Text = value
            End Set
        End Property

        Private _container_cssclass As String
        Public Property container_cssclass() As String
            Get
                Return _container_cssclass
            End Get
            Set(ByVal value As String)
                _container_cssclass = value
            End Set
        End Property

        Private _message As LiteralControl
        Public Property message() As String
            Get
                EnsureChildControls()
                Return _message.Text
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _message.Text = value
            End Set
        End Property



        Private _ValidationGroup As String
        Public Property ValidationGroup() As String
            Get
                EnsureChildControls()
                Return _lb_start.ValidationGroup
            End Get
            Set(ByVal value As String)
                EnsureChildControls()
                _lb_start.ValidationGroup = value
                _lb_commit.ValidationGroup = value
            End Set
        End Property

        Private _CausesValidation As Boolean
        Public Property Causesvalidation() As Boolean
            Get
                EnsureChildControls()
                Return _lb_start.CausesValidation
            End Get
            Set(ByVal value As Boolean)
                EnsureChildControls()
                _lb_start.CausesValidation = value
                _lb_commit.CausesValidation = value
            End Set
        End Property



#End Region

    End Class

End Namespace

